home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / usum < prev    next >
Text File  |  1995-03-31  |  3KB  |  108 lines

  1.  
  2.  
  3. The built in unit system of the HP48 has one disadvantage, the fact that, say,
  4. 0.75_h 2 * is given as 1.5_h rather than 1_h+30_min. This program performs such
  5. conversions
  6.  
  7. The basic program is \->USUM which looks at the list of lists UNIT.L. UNIT.L's
  8. sublists each consist of unit objects each with coefficient 1 arranged in
  9. decreasing order of size (look at the example I have given to get the format).
  10. All the units in a sublist must have the same dimensions. The program can only
  11. (obviously) work with units contained in UNIT.L. If you try to use another
  12. unit, it will report an error ("Unit Not Found")
  13. The program UCONV is similar to \->USUM, but instead of taking it's list of
  14. units by search UNIT.L for an appropriate sublist, it takes a simple list of
  15. units in Top of stack and performs the conversion on the unit object 2nd on
  16. stack. The List must be arranged in decreasing order of size as above.
  17. The program USEARCH searches the UNIT.L variable for the sublist that contains
  18. the unit in top of stack and returns the original unit in 2nd on stack and the
  19. appropriate list in Top of Stack (thus the stack is left in the correct form
  20. for UCONV).
  21.  
  22. The demonstration UNIT.L variable contains the following Units :
  23.  
  24. 1_mi 1_chain 1_rd 1_yd 1_ft 1_in        (1st sublist - length)
  25. 1_mi 2 1_acre 1_yd 2 1_ft 2 1_in 2      (2nd sublist - area)
  26. 1_bbl 1_bu 1_pk 1_galUK 1_qt 1_pt 1_cu 1_tbsp 1_tsp  (3rd sublist - volume)
  27. 1_yr 1_d 1_h 1_min 1_s                   (4th sublist - time)
  28. 1_tonUK 1_lb 1_oz                        (5th sublist - mass)
  29.  
  30. Note that due to the fact that many of the old units had several definitions,
  31. and the fact that 1_yr <> 365_d, the answer may not be what you expect. It may
  32. be useful to define some units of your own to get round this problem
  33.  
  34. -tony Duell
  35.    Janet: ARD@UK.AC.BRIS.SIVA
  36.   Bitnet: ARD@SIVA.BRIS.AC.UK
  37. ------------------>8---------------------->8--------------------->8----------
  38.  
  39. %%HP: T(3)A(R)F(.);
  40. DIR
  41.   \->USUM
  42.     \<< USEARCH UCONV
  43.     \>>
  44.   UNIT.L $ $ '1_mi'
  45. '1_chain' '1_rd' '1
  46. _yd' '1_ft' '1_in'
  47.   $ '1_mi 2' '1_
  48. acre' '1_yd 2' '1_
  49. ft 2' '1_in 2'   $
  50. '1_bbl' '1_bu' '1_
  51. pk' '1_galUK' '1_qt
  52. ' '1_pt' '1_cu' '1_
  53. tbsp' '1_tsp'   $ '
  54. 1_yr' '1_d' '1_h' '
  55. 1_min' '1_s'   $ '1
  56. _tonUK' '1_lb' '1_
  57. oz'    
  58.   UA
  59.     \<< DUP SIZE 1 -
  60. 2 SWAP SUB + "+" +
  61.     \>>
  62.   UCONV
  63.     \<< DUP SIZE \-> u
  64. ul sz
  65.       \<< "" 1 sz 1 -
  66.         FOR n u ul
  67. n GET CONVERT
  68.           IF DUP
  69. UVAL IP 0 \=/
  70.           THEN OBJ\->
  71. OVER FP OVER \->UNIT
  72. 'u' STO SWAP IP
  73. SWAP \->UNIT \->STR UA
  74.           ELSE DROP
  75.           END
  76.         NEXT u ul
  77. sz GET CONVERT DUP
  78. UVAL
  79.         IF 0 \=/
  80.         THEN \->STR
  81. UA
  82.         ELSE DROP
  83.         END DUP
  84. SIZE 1 - 1 SWAP SUB
  85. "'" + "'" SWAP +
  86. OBJ\->
  87.       \>>
  88.     \>>
  89.   USEARCH
  90.     \<< 0 \-> n
  91.       \<<
  92.         DO 'n' INCR
  93.           IF UNIT.L
  94. SIZE >
  95.           THEN
  96. "Unit not found"
  97. DOERR
  98.           END
  99. UNIT.L n GET OVER
  100. OBJ\-> SWAP DROP POS
  101.         UNTIL 0 >
  102.         END UNIT.L
  103. n GET
  104.       \>>
  105.     \>>
  106. END
  107.  
  108.